/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.asportoonline.tags;

import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 *
 * @author fe
 */
public class OrarioLocaleTag extends SimpleTagSupport {
    private String ora;

    public String getOra() {
        return ora;
    }

    public void setOra(String ora) {
        this.ora = ora;
    }
    
    @Override
    public void doTag() throws JspException {
        JspWriter out = getJspContext().getOut();
        String hour = getOra();
        
        if(hour == null) {
            hour = "00:00";
        }
        
        try {
            
            for(int i=0; i<24; i++) {
                if(i<10) {
                    
                    if(hour.equals("0"+i+":00")) {
                        out.print("<option value=\"0"+i+":00\" selected=\"selected\">0"+i+":00</option>");
                    }
                    else {
                        out.print("<option value=\"0"+i+":00\">0"+i+":00</option>");
                    }
                    
                    if(hour.equals("0"+i+":30")) {
                        out.print("<option value=\"0"+i+":30\" selected=\"selected\">0"+i+":30</option>");
                    }
                    else {
                        out.print("<option value=\"0"+i+":30\">0"+i+":30</option>");
                    }
                    
                }
                else {
                    
                    if(hour.equals(i+":00")) {
                        out.print("<option value=\""+i+":00\" selected=\"selected\">"+i+":00</option>");
                    }
                    else {
                        out.print("<option value=\""+i+":00\">"+i+":00</option>");
                    }
                    
                    if(hour.equals(i+":30")) {
                        out.print("<option value=\""+i+":30\" selected=\"selected\">"+i+":30</option>");
                    }
                    else {
                        out.print("<option value=\""+i+":30\">"+i+":30</option>");
                    }
                    
                }
            }
            
        } catch(IOException ex) {
            throw new JspException("Errore in OrarioLocaleTag tag");
        }
    }
}
